﻿/*using CardMaker.Library.Models;

namespace CardMaker.Library.Services;

public class MainImageStorage : IMainImageStorage
{
    private const string type = "png";
    private string path = "";
    private readonly string _mainImageBox = "MainImageBox";
    public Task InitializeAsync()
    {
        path = Path.Combine(
            Environment.GetFolderPath(Environment.SpecialFolder
                .LocalApplicationData), _mainImageBox);
        if (!Directory.Exists(path))
            Directory.CreateDirectory(path);
        return Task.CompletedTask;
    }

    public async Task<byte[]> GetMainImagesAsync(CardTemplate cardTemplate,string name)
    {
        var imageMemoryStream = new MemoryStream();
        var filePath = Path.Combine(path, cardTemplate.CardTemplateId + "." + name + "." + type);
        try
        {
            await using var imageFileStream =
                new FileStream(filePath, FileMode.Open);
            await imageFileStream.CopyToAsync(imageMemoryStream); //文件流转换到内存流
        }
        catch (IOException)
        {
            //todo
        }
        finally
        {
            imageMemoryStream.Close();
        }
        return imageMemoryStream.ToArray();
    }

    public async Task SaveMainImageAsync(CardTemplate cardTemplate,string name, byte[] mainImageBytes)
    {
        var filePath = Path.Combine(path,
            cardTemplate.CardTemplateId + "." + name + "." + type);
        if (File.Exists(filePath))
            //todo 已经存在提示覆盖
            return;
        await using var imageFileStream =
            new FileStream(filePath, FileMode.Create);
        await imageFileStream.WriteAsync(
            mainImageBytes, 0,
            mainImageBytes.Length);
    }
}*/